package com.pwc.conversionTool.biz.sendSoap;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;



import com.googlecode.objectify.Key;
import com.pwc.conversionTool.biz.ProjectBiz;
import com.pwc.conversionTool.dataAdaptor.DataAdaptor;
import com.pwc.conversionTool.dataAdaptor.IDataAdaptor;
import com.pwc.conversionTool.entity.DataType;
import com.pwc.conversionTool.entity.Operation;
import com.pwc.conversionTool.entity.Task;
import com.pwc.conversionTool.entity.TaskLog;

public class DataAdaptorProcess {
	
	private Task task;
	
	private TaskLog taskLog=new TaskLog();
	
	private Operation operation=null;
	
	
	
	public  DataAdaptorProcess(Task task)
	{
		this.task=task;
		Key<Operation> operationkey = task.getOperation();		
		ProjectBiz projectBiz = new ProjectBiz();		
		operation = projectBiz.getOperationByKey(operationkey);
	}
	
	public  DataAdaptorProcess(Task task,TaskLog taskLog )
	{
		this.task=task;
		this.taskLog=taskLog;
		Key<Operation> operationkey = task.getOperation();		
		ProjectBiz projectBiz = new ProjectBiz();		
		operation = projectBiz.getOperationByKey(operationkey);
	}
	
	
	
	
	public List<IDataAdaptor> getDataAdaptors() throws IOException
	{
		List<String> keys=new ArrayList<String>();
		IDataAdaptorProcess dataAdaptorProcess=null;
		List<IDataAdaptor> dataAdaptors = new ArrayList<IDataAdaptor>();
		if (operation.getDataAdaptorData().getDataType().equalsIgnoreCase(DataType.CSV))
		{
			keys = task.getFiles();
			dataAdaptorProcess=new CsvProcess(taskLog,operation, keys);
			
		}else if(operation.getDataAdaptorData().getDataType().equalsIgnoreCase(DataType.EXCEL))
		{
			keys = task.getFiles();
			dataAdaptorProcess=new ExcelProcess(taskLog,operation, keys);
		}
		
		dataAdaptors=dataAdaptorProcess.getDataAdaptors();
		
		return dataAdaptors;
	}
	
	
	

}
